﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<ModelClassesLinqToSql.Views.Movie.DetailViewModel>" %>
<%@ Import Namespace="ModelClassesLinqToSql.Domain.Models" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Details
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<% using(Html.BeginForm()) { %>

<h2>Details</h2>

<table>
    <tr>
        <td><%= Html.LabelFor(m => m.Name, "Movie Name:") %></td>
        <td><%= Html.TextBoxFor(m => m.Name) %>&nbsp;<%= Html.ValidationMessageFor(m => m.Name) %></td>
    </tr>
    <tr>
        <td><%= Html.LabelFor(m => m.Released, "Released Date:") %></td>
        <td><%= Html.TextBoxFor(m => m.Released) %>&nbsp;<%= Html.ValidationMessageFor(m => m.Released) %></td>
    </tr>
    <tr>
        <td><%= Html.LabelFor(m => m.ProductionCompanyId, "Production Company:") %></td>
        <td><%= Html.DropDownListFor(m => m.ProductionCompanyId,
                   new SelectList(ViewBag.ProductionCompanies, "Id", "Name"))%>&nbsp;<%= Html.ValidationMessageFor(m => m.ProductionCompanyId) %></td>
    </tr>
    <tr>
        <td valign="top">Employees:</td>
        <td><table>
                <thead>
                    <tr>
                        <th>Employee Name</th>
                        <th>Job Title</th>
                        <th><a class="addLink" href="#">Assign an Employee</a></th>
                    </tr>
                </thead>
                <tbody class="employeeRows">
                    <% if(Model.Employees.Count() > 0) {%>
                    <% foreach (EmployeeJobTitleComposite em in Model.Employees)
                       { %>
                    <tr data-employee-id="<%= em.Employee.Id %>" data-job-title-id="<%= em.JobTitle.Id %>"  data-action="0">
                        <td><%= "#" + em.Employee.Id + " " + em.Employee.FirstName + " " + em.Employee.LastName %></td>
                        <td><%= em.JobTitle.Title %></td>
                        <td><a href="#" class="editLink">Edit</a>&nbsp;&nbsp;<a href="#" class="deleteLink">Unassign</a></td>
                    </tr>
                    <% } %>
                    <% } else {%>
                    <tr>
                        <td colspan="2">There are currently no employees.</td>
                        <td>&nbsp;</td>
                    </tr>
                    <% } %>
                </tbody>
        </table>
        <input type="hidden" id="EmployeeChangeList" name="EmployeeChangeList" value="" /></td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td><input type="submit" value="Submit" /></td>
    </tr>
</table>
<div></div>
<table id="employeeTemplate" style="visibility:hidden;">
    <tr data-employee-id="0" data-job-title-id="0" data-action="1">
        <td class="employeeName">Employee Name</td>
        <td class="jobTitle">Job Title</td>
        <td><a href="#" class="editLink">Edit</a>&nbsp;&nbsp;<a href="#" class="deleteLink">Unassign</a></td>
    </tr>
</table>
<% } %>
<!--add/edit dialog-->
<div id="DetailDialog" style="display:none">
    <div>Employee:&nbsp;
        <select id="EmployeeList">
        <% foreach(Employee e in ViewBag.Employees) { %>
            <option value="<%=e.Id%>">#<%=e.Id + " " + e.FirstName + " " + e.LastName%></option>
        <%} %>
        </select>
        Job Title:&nbsp;
        <select id="JobTitleList">
        <% foreach (JobTitle j in ViewBag.JobTitles)
           { %>
            <option value="<%=j.Id%>"><%=j.Title%></option>
        <%} %>
        </select>&nbsp;
        <input type="button" value="Submit" />
        <input id="DialogAction" type="hidden" value="0" />
        <input id="CurEmployeeId" type="hidden" value="0" />
        <input id="CurJobTitleId" type="hidden" value="0" />
        <div id="DialogError"></div>
    </div>
</div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="EmbeddedJavaScript" runat="server">
<script type="text/javascript" src="<%= Url.Content("~/Views/Movie/Detail.js") %>">
</script>
<script type="text/javascript">
$(function () {Views.Movie.Detail().start();});
</script>
</asp:Content>